<script type="text/javascript">
$('form').submit(function() {
  if(!$('form').validationEngine({returnIsValid:true})===false){
        $.post($(this).attr("action"),$(this).serialize(),function(data){
            $("#body").html(data);
            $('#example').dataTable()});
    }
  return false;
});
</script>
<form action="index.php?page=privileges&action=save" method="post">
    <table>
        <tr>
            <td>
                 Privilege name
            </td>
            <td>
                <input type="text" name="name"  id="name" class="validate[required,length[0,50]]" <?php if(isset($data)) echo "value ='".$data->name."' ";?>/>
                <?php if(isset($data->id)) echo "<input type='hidden' name='id' id='id' value='{$data->id}'";?>
            </td>
        </tr>
        <tr>
            <td>
                 Basic Quantity
            </td>
            <td>
                <input type="text" name="basicQuantity"  id="basicQuantity" class="validate[required,length[0,50]]" <?php if(isset($data)) echo "value ='".$data->basicQuantity."' ";?>/>
                <?php if(isset($data->id)) echo "<input type='hidden' name='id' id='id' value='{$data->id}'";?>
            </td>
        </tr>
        <tr>
            <td>
                 Type
            </td>
            <td>
                <select id="typeId" name="typeId">
                    <?php
                        foreach ($types as $type){
                            $selected = "";
                            if($type->id  == $data->typeId)
                                    $selected = "selected";
                            echo("<option value='{$type->id}' {$selected}> {$type->name} </option>");
                        }
                    ?>
                </select>
            </td>
        </tr>
        <tr>
            <td>
                <input type="submit" value="save"/>
            </td>
        </tr>
    </table>
</form>
